package com.squareup.picasso;

import android.content.Context;
import android.content.res.AssetManager;
import android.net.Uri;

import com.squareup.picasso.Picasso.LoadedFrom;

import java.io.IOException;

final class AssetRequestHandler extends RequestHandler {
    private final AssetManager assetManager;

    public AssetRequestHandler(Context context) {
        this.assetManager = context.getAssets();
    }

    public final boolean canHandleRequest(Request result) {
        Uri uri = result.uri;
        return "file".equals(uri.getScheme()) && !uri.getPathSegments().isEmpty() && "android_asset".equals(uri.getPathSegments().get(0));
    }

    public final Result load(Request request) throws IOException {
        return new Result(this.assetManager.open(request.uri.toString().substring(22)), LoadedFrom.DISK);
    }
}

